<?php
class AdviseAction extends Action{
	
    function _initialize() {
		
	}
	public function index(){
	//print_r($this->user);
	 $advise = M('advise');
	 $count = $advise->count(); 
	 $p = new Page ( $count, 10 );
	 
	 $list = $advise->limit($p->firstRow.','.$p->listRows)->order('ctime DESC')->findAll ();
	 $page = $p->show ();
	 $this->assign ( "page", $page );	 
	 
	 $this->assign('list',$list);
	 $this->assign('admin_level',$this->user['admin_level']);
     $this->setTitle('给我们提建议');
     $this->display();
	
	}
	public function add(){
	if(md5(intval($_POST['verify']))!=$_SESSION['verify']){
	  $this->error('验证码错误');
	  exit;
	 }
	if($this->user){
	 $data['from_uid']  = $this->mid;
	 $data['from_uname']= $this->user['uname'];
	 }else{
	 $data['from_uid']  = 0;
	 $data['from_uname']= 匿名用户;
	 }
	 $data['content']   =t($_POST['adv_content']);
	 $data['ctime']     =time();
	 $rel=M('advise')->add($data);
	 if($rel){
	 
	 $this->success('添加成功');
	 }else{
	 $this->error('添加失败');
	 }
	
	}
	public function deladv(){
	   $id=empty($_GET['id'])?0:intval($_GET['id']);
	   if(!$id){
	      echo 0;
		  exit;
	   }
	    if(M('advise')->where('adv_id='.$id)->delete()){
		    echo 1;
			exit;
		}else{
		    echo 0;
			exit;
		}
	  /* $res=M('advise')->where('adv_id='.$id)->delete();
	   if($res){
	     $this->success('成功');
	   }else{
	   $this->error('失败');
	   }*/
	}
	public function verify() {
        require_once(SITE_PATH.'/addons/libs/Image.class.php');
        require_once(SITE_PATH.'/addons/libs/String.class.php');
    	Image::buildImageVerify();
	}
}
?>